using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using System.Web.Routing;
using Thor.Models;
using Thor.WebRole.Services;
using Thor.Common;
using Thor.Domain;
using Thor.Domain.Configuration;

namespace Thor.WebRole.Controllers
{
    public class CalendarController : AuthenticatedController
    {
        public ActionResult Index(string id)
        {
            var result = this.CalendarAuthenticationRequired(id);

            if (result != null)
                return result;

            var svc = new CalendarManagerDomainService();
            var calendar = svc.GetCalendar(id);

            SingleDayCalendar model = new SingleDayCalendar(calendar);
            return View("Details", model);
        }

        public ActionResult Booked(string id, string message)
        {
            var result = this.CalendarAuthenticationRequired(id);

            if (result != null)
                return result;

            var svc = new CalendarManagerDomainService();
            var calendar = svc.GetCalendar(id);

            SingleDayCalendar model = new SingleDayCalendar(calendar);
            model.Message = message;

            return View("Details", model);
        }

        public ActionResult NotFound()
        {
            return View("NotFound");
        }

        public ActionResult Book(CalendarEntry entry)
        {
            var result = this.CalendarAuthenticationRequired(entry.CalendarEmail);

            if (result != null)
                return result;

            return RedirectToAction("Index", "Booking", entry);
        }
    }

}
